#ifndef  FRAME_SERVICE_H
#define  FRAME_SERVICE_H


#include <unordered_map>
#include "Util.h"
#include "Interface.h"

namespace frame {

class ImplFactory;
class ServiceImpl;

class Service : public IService {
public:
    explicit Service(std::shared_ptr<ImplFactory> factory);
    ~Service() override ;

    int start() override;
    int run() override ;
    void stop() override ;

    uint64_t add(IRunnable::Ptr runnable) override ;
    void remove(uint64_t id) override ;
    IRunnable::Ptr get(uint64_t id) override;
    size_t size() override {
        return runObjects.size();
    }

public:
    std::shared_ptr<ServiceImpl> getImpl() const override{
        return impl;
    }
    std::shared_ptr<ImplFactory> getFactory() const override{ 
        return factory;
    }

private:
    std::shared_ptr<ImplFactory> factory;
    std::shared_ptr<ServiceImpl> impl;
    UniqueNumber numbers;
    std::unordered_map<uint64_t, IRunnable::Ptr> runObjects;
};

} //end of namespace frame
#endif   /* FRAME_SERVICE_H */
